// pages/VerifyMobile/VerifyMobile.js
var request = require("../../utils/request.js")
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    lockMobile: '', //手机号 加密
    mobile: '', // 手机号
    code: '',//验证码
    id: '',//报告id
    isShow: false, // 清除输入的验证码
    radioCheck: false, //判断是否勾选协议radio,默认未勾选
    isActive: false, //判断提交按钮可否点击 a不可点击 b 可点击
    verifyText: '获取验证码',
    chooseSize: false,
    animationData: {},
    showModal: false,
    msg: "",
    appointMsg: "",
    //是否显示modal弹窗
    isShowModal:false,
    //控制底部是一个按钮还是两个按钮，默认两个
    single: {
      type: Boolean,
      value: false 
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let lockMobile = options.mobile.substr(0, 3) + '******' + options.mobile.substr(9, 2)
    this.setData({
      lockMobile: lockMobile,
      id: options.id,
      mobile: options.mobile
    })
    console.log(options)
    wx.showShareMenu({ menus: ['shareAppMessage', 'shareTimeline']})
  },
/**
 * 用户点击右上角分享
 */
onShareAppMessage (res) {
  return {
    title: '迪佳极视',
    path: 'pages/index/index',
    // imageUrl:'这个是显示的图片，不写就默认当前页面的截图',
    success: function (shareTickets) {
      console.info(shareTickets + '成功');
      // 转发成功
    },
    fail: function (res) {
      console.log(res + '失败');
      // 转发失败
    },
    complete:function(res){
      // 不管成功失败都会执行
    }
  }
},
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.toastDialog = this.selectComponent("#toastDialog"); //此处id和页面的 wxml中的id一致

  },
  //获取input 输入手机号的值
  getInputValue: function (e) {
    let isActive = false
    if (this.data.radioCheck && e.detail.value.length == 6) {
      isActive = true
    }
    this.setData({
      isActive: isActive,
      isShow: true,
      code: e.detail.value
    })
  },
  //清除输入的验证码
  queryClear: function (e) {
    console.log(e)
    console.log(this.data.code)
    this.setData({
      code: '',
      isShow: false
    })
    console.log(this.data.code)

  },
  //监听radio
  radioClick: function (event) {
    var radioCheck = this.data.radioCheck;
    let isActive = false
    if (!radioCheck && this.data.code.length == 6) {
      isActive = true
    }
    this.setData({
      "radioCheck": !radioCheck,
      isActive: isActive
    });
  },
  //获取验证码
  getVerifyCode: function () {
    var that = this;
    request.postData('app/createCode', { mobile: that.data.mobile }, function (res) {
      if (res.code == 0) {
        let time = 60;
        let timer = setInterval(() => {
          if (time > 0) {
            time--;
            that.setData({
              verifyText: time + 'S'
            })
          } else {
            that.setData({
              isVerif: false,
              verifyText: '重发验证码'
            })
            clearInterval(timer)
          }
        }, 1000);
      } else {
        that.toastDialog.showDialog({ code: res.code, message: res.message, timeout: true });
      }
    }, function (res) {
      that.toastDialog.showDialog({ code: res.code, message: res.message, timeout: true });
    });
  },
  //提交验证码
  gotoReportList: function () {
    var that = this;
    if (!that.data.radioCheck) {
      that.toastDialog.showDialog({ code: 'warinning', message: '请勾选同意《青少年隐私保护协议》后再查看报告', totastType: 'black', timeout: true });
      console.log("未勾选")
      return false
    }
    if (!that.data.isActive) {
      this.setData({
        msg:'请输入六位数验证码',
        isShowModal: true
      })
      return false
    }
    let data = {
      mobile: that.data.mobile,
      code: that.data.code,
      studentId: that.data.id
    }
    wx.navigateTo({
      url: '../seeArchives/seeArchives?mobile='+that.data.mobile+'&studentId='+that.data.id+'&code='+that.data.code
    })
  },
  gotoLink:function(){
    var that = this
    that.setData({
      link: "https://di.plus/dj-policy-qsn.html",
      title: "青少年隐私保护协议",
    })
    wx.navigateTo({
      url: '../ys/ys?link=' + that.data.link + '&title=' + that.data.title,
    })
  },
  clickMask() {
    // 点击modal背景关闭遮罩层，如果不需要注释掉即可
    this.setData({isShowModal: false})
  },
 // 点击取消按钮的回调函数
  cancel() {
    this.setData({ isShowModal: false })
    this.triggerEvent('cancel')  //triggerEvent触发事件
  },
  // 点击确定按钮的回调函数
  confirm() {
    this.setData({ isShowModal: false })
    this.triggerEvent('confirm')
  }
})